package com.jinbei.common.base;

import com.jinbei.common.Enum.ConstantsEnum;
import org.springframework.stereotype.Component;

/**
 * @author zflu
 * response entity
 * Created by zflu on 2018/7/8.
 */
@Component
public class ResponseBaseEntity {

    /**
     * @Author zflu
     * @Description 返回成功
     * @Date 2018/7/8 10:39
     * @Param []
     * @return com.jinbei.common.ResponseBase
     **/
    public static ResponseBase setResultSuccess() {
        return setResult(ConstantsEnum.SUCCESS_200, null);
    }

    /**
     * @Author zflu
     * @Description 返回数据成功200
     * @Date 2018/7/8 10:41
     * @Param [data]
     * @return com.jinbei.common.ResponseBase
     **/
    public static ResponseBase setResultSuccess(Object data) {
        return setResult(ConstantsEnum.SUCCESS_200, data);
    }

    /**
     * @Author zflu
     * @Description 返回数据成功201
     * @Date 2018/7/8 10:42
     * @Param [data]
     * @return com.jinbei.common.ResponseBase
     **/
    public static ResponseBase setResultQqSuccess(Object data) {
        return setResult(ConstantsEnum.SUCCESS_201, data);
    }

    /**
     * @Author zflu
     * @Description 返回失败
     * @Date 2018/7/8 10:42
     * @Param
     * @return com.jinbei.common.ResponseBase
     **/
    public static ResponseBase setResultError(ConstantsEnum constantsEnum){
        if(constantsEnum == null){
            constantsEnum = ConstantsEnum.ERROR_500;
        }
        return setResult(constantsEnum, null);
    }


    /**
     * @Author zflu
     * @Description 自定义返回结果
     * @Date 2018/7/8 10:38
     * @Param [code, msg, data]
     * @return com.jinbei.common.ResponseBase
     **/
    public static ResponseBase setResult(ConstantsEnum constantsEnum, Object data) {
        ResponseBase responseBase = new ResponseBase();
        responseBase.setCode(constantsEnum.getCode());
        responseBase.setMsg(constantsEnum.getMsg());
        if (data != null){
            responseBase.setData(data);
        }
        return responseBase;
    }

}
